﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="Environment.cs" company="Anton Frattaroli">
//   Copyright (c) Anton Frattaroli. All rights reserved.
// </copyright>
// <summary>
//   Defines the Environment class.
// </summary>
// --------------------------------------------------------------------------------------------------------------------
namespace Lidocaine.BusinessLogic
{
    using System;
    using System.Configuration;
    using System.Web;
    using Lidocaine.BusinessObjects;
    
    /// <summary>
    /// Defines the Environment class.
    /// </summary>
    public static class Environment
    {
        /// <summary>
        /// Stores the database connection string for this application.
        /// </summary>
        private static readonly string LidocaineConnectionString = ConfigurationManager.ConnectionStrings[((AppConfigSection)ConfigurationManager.GetSection("lidocaine/appConfig")).ConnectionStringName].ConnectionString;

        /// <summary>
        /// Stores the URL for the logon page.
        /// </summary>
        private static readonly Uri LidocaineLogOnUrl = ((AppConfigSection)ConfigurationManager.GetSection("lidocaine/appConfig")).LogOnUrl;

        /// <summary>
        /// Stores the URL for the error page.
        /// </summary>
        private static readonly Uri LidocaineErrorUrl = ((AppConfigSection)ConfigurationManager.GetSection("lidocaine/appConfig")).ErrorUrl;

        /// <summary>
        /// Stores the title of the website.
        /// </summary>
        private static readonly string LidocaineTitle = ((AppConfigSection)ConfigurationManager.GetSection("lidocaine/appConfig")).Title;

        /// <summary>
        /// Stores the (host) domain of the website.
        /// </summary>
        private static readonly string LidocaineDomain = ((AppConfigSection)ConfigurationManager.GetSection("lidocaine/appConfig")).Domain;

        /// <summary>
        /// Stores the path to the directory where static files are saved and served from.
        /// </summary>
        private static readonly string LidocaineStaticFilesDirectory = HttpContext.Current.Server.MapPath("~/") + "Static_Files";

        /// <summary>
        /// Stores a boolean value indicating whether or not to use SSL.
        /// </summary>
        private static readonly bool LidocaineUseSsl = ((AppConfigSection)ConfigurationManager.GetSection("lidocaine/appConfig")).UseSsl;

        /// <summary>
        /// Stores a boolean value indicating whether or not to allow setup.
        /// </summary>
        private static readonly bool LidocaineAllowSetup = ((AppConfigSection)ConfigurationManager.GetSection("lidocaine/appConfig")).AllowSetup;
        
        /// <summary>
        /// Gets the database connection string for the Lidocaine instance.
        /// </summary>
        public static string ConnectionString
        {
            get
            {
                return LidocaineConnectionString;
            }
        }

        /// <summary>
        /// Gets the URL for the logon page.
        /// </summary>
        public static Uri LogOnUrl
        {
            get
            {
                return LidocaineLogOnUrl;
            }
        }
        
        /// <summary>
        /// Gets the URL for the error page.
        /// </summary>
        public static Uri ErrorUrl
        {
            get
            {
                return LidocaineErrorUrl;
            }
        }

        /// <summary>
        /// Gets the title of the website.
        /// </summary>
        public static string Title
        {
            get
            {
                return LidocaineTitle;
            }
        }

        /// <summary>
        /// Gets the (host) domain of the website.
        /// </summary>
        public static string Domain
        {
            get
            {
                return LidocaineDomain;
            }
        }

        /// <summary>
        /// Gets the directory where static files are saved and served from.
        /// </summary>
        public static string StaticFilesDirectory
        {
            get
            {
                return LidocaineStaticFilesDirectory;
            }
        }

        /// <summary>
        /// Gets a value indicating whether or not to use SSL.
        /// </summary>
        public static bool UseSsl
        {
            get
            {
                return LidocaineUseSsl;
            }
        }

        /// <summary>
        /// Gets a value indicating whether or not to allow setup.
        /// </summary>
        public static bool AllowSetup
        {
            get
            {
                return LidocaineAllowSetup;
            }
        }
    }
}